package com.heartline.service;

import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.Route;
import com.blade.mvc.annotation.TEXT;
import com.soecode.wxtools.api.IService;
import com.soecode.wxtools.api.WxConsts;
import com.soecode.wxtools.api.WxService;
import com.soecode.wxtools.bean.PreviewSender;
import com.soecode.wxtools.bean.SenderContent;
import com.soecode.wxtools.bean.SenderFilter;
import com.soecode.wxtools.bean.WxTagSender;
import com.soecode.wxtools.bean.result.SenderResult;
import com.soecode.wxtools.exception.WxErrorException;
import lombok.extern.slf4j.Slf4j;

/**
 * 推送服务
 * Created by Administrator on 2018/6/3 0003.
 */
@Deprecated
@Slf4j
//@Path("api")
public class PushService {

    private IService iService = new WxService();

    @Route("push")
    @TEXT
    public String push(@Param String str) {
        WxTagSender sender = new WxTagSender();
        //设置哪些组需要接受群发
        sender.setFilter(new SenderFilter(true, 0));
        //群发文本内容
        sender.setText(new SenderContent.Text(str));
        sender.setMsgtype(WxConsts.XML_MSG_TEXT);

        try {
            SenderResult result = iService.sendAllByTag(sender);
            log.info(result.toString());
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        return "success";
    }

    @Route("send")
    @TEXT
    public String send() {
        PreviewSender sender = new PreviewSender();
        sender.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
        sender.setText(new SenderContent.Text("文本内容"));
        sender.setTouser("oa3dpwEou5FsSEEhOsjTFm9MDaW8");
        try {
            SenderResult result = iService.sendAllPreview(sender);
            log.info(result.toString());
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
